package com.caigou.modules.query.ui.assistant

import android.os.Bundle
import android.text.TextUtils
import android.util.SparseBooleanArray
import android.widget.CompoundButton
import androidx.activity.viewModels
import androidx.core.util.isNotEmpty
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.caigou.comm.base.bean.PrizeBallBean
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseActivity
import com.caigou.comm.base.ext.Resource
import com.caigou.comm.base.ext.observe
import com.caigou.comm.base.ext.showToast
import com.caigou.comm.base.widget.SpaceItemDecoration
import com.caigou.modules.query.adpter.PrizeBallItemAdapter
import com.caigou.modules.query.databinding.ActivityAssistantBinding
import com.caigou.modules.query.ext.PrizeBallIdx
import com.caigou.modules.query.viewmodel.AssistantViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.util.*
import kotlin.collections.HashMap

/**
 * @author #Suyghur.
 * Created on 2021/12/22
 */
@Route(path = RouterPath.Query.PAGE_ASSISTANT)
@AndroidEntryPoint
class AssistantActivity : BaseActivity(), CompoundButton.OnCheckedChangeListener {

    private lateinit var binding: ActivityAssistantBinding
    private val assistantViewModel: AssistantViewModel by viewModels()

    private val mAdapter: PrizeBallItemAdapter by lazy {
        PrizeBallItemAdapter(mutableListOf())
    }

    private val single = SparseBooleanArray()
    private val multiDaDanDaShuangXiaoDanXiaoShuang = SparseBooleanArray()
    private val multiHeDanHeShuangHeDaHeXiao = SparseBooleanArray()
    private val multiWuxing = SparseBooleanArray()
    private val multiColor = SparseBooleanArray()
    private val multiColorDanShuang = SparseBooleanArray()
    private val multiShengXiao = SparseBooleanArray()
    private val multiWeiShu = SparseBooleanArray()
    private val multiTouShu = SparseBooleanArray()
    private val multiMenShu = SparseBooleanArray()
    private val multiDuanShu = SparseBooleanArray()
    private val multiHeShu = SparseBooleanArray()
    private val multiTouDAnTouShuang = SparseBooleanArray()

    private val balls = HashMap<Int, MutableList<PrizeBallBean>>()
    private val danBalls = mutableListOf<PrizeBallBean>()
    private val shuangBalls = mutableListOf<PrizeBallBean>()
    private val daBalls = mutableListOf<PrizeBallBean>()
    private val xiaoBalls = mutableListOf<PrizeBallBean>()
    private val daDanBalls = mutableListOf<PrizeBallBean>()
    private val daShuangBalls = mutableListOf<PrizeBallBean>()
    private val xiaoDanBalls = mutableListOf<PrizeBallBean>()
    private val xiaoShuangBalls = mutableListOf<PrizeBallBean>()
    private val heDanBalls = mutableListOf<PrizeBallBean>()
    private val heShuangBalls = mutableListOf<PrizeBallBean>()
    private val heDaBalls = mutableListOf<PrizeBallBean>()
    private val heXiaoBalls = mutableListOf<PrizeBallBean>()
    private val jinBalls = mutableListOf<PrizeBallBean>()
    private val muBalls = mutableListOf<PrizeBallBean>()
    private val shuiBalls = mutableListOf<PrizeBallBean>()
    private val huoBalls = mutableListOf<PrizeBallBean>()
    private val tuBalls = mutableListOf<PrizeBallBean>()
    private val hongBalls = mutableListOf<PrizeBallBean>()
    private val lanBalls = mutableListOf<PrizeBallBean>()
    private val lvBalls = mutableListOf<PrizeBallBean>()
    private val jiaQinBalls = mutableListOf<PrizeBallBean>()
    private val yeShouBalls = mutableListOf<PrizeBallBean>()
    private val hongDanBalls = mutableListOf<PrizeBallBean>()
    private val hongShuangBalls = mutableListOf<PrizeBallBean>()
    private val lanDanBalls = mutableListOf<PrizeBallBean>()
    private val lanShuangBalls = mutableListOf<PrizeBallBean>()
    private val lvDanBalls = mutableListOf<PrizeBallBean>()
    private val lvShuangBalls = mutableListOf<PrizeBallBean>()
    private val shuBalls = mutableListOf<PrizeBallBean>()
    private val niuBalls = mutableListOf<PrizeBallBean>()
    private val huBalls = mutableListOf<PrizeBallBean>()
    private val tuziBalls = mutableListOf<PrizeBallBean>()
    private val longBalls = mutableListOf<PrizeBallBean>()
    private val sheBalls = mutableListOf<PrizeBallBean>()
    private val maBalls = mutableListOf<PrizeBallBean>()
    private val yangBalls = mutableListOf<PrizeBallBean>()
    private val houBalls = mutableListOf<PrizeBallBean>()
    private val jiBalls = mutableListOf<PrizeBallBean>()
    private val gouBalls = mutableListOf<PrizeBallBean>()
    private val zhuBalls = mutableListOf<PrizeBallBean>()
    private val wei0Balls = mutableListOf<PrizeBallBean>()
    private val wei1Balls = mutableListOf<PrizeBallBean>()
    private val wei2Balls = mutableListOf<PrizeBallBean>()
    private val wei3Balls = mutableListOf<PrizeBallBean>()
    private val wei4Balls = mutableListOf<PrizeBallBean>()
    private val wei5Balls = mutableListOf<PrizeBallBean>()
    private val wei6Balls = mutableListOf<PrizeBallBean>()
    private val wei7Balls = mutableListOf<PrizeBallBean>()
    private val wei8Balls = mutableListOf<PrizeBallBean>()
    private val wei9Balls = mutableListOf<PrizeBallBean>()
    private val daWeiBalls = mutableListOf<PrizeBallBean>()
    private val xiaoWeiBalls = mutableListOf<PrizeBallBean>()
    private val tou0Balls = mutableListOf<PrizeBallBean>()
    private val tou1Balls = mutableListOf<PrizeBallBean>()
    private val tou2Balls = mutableListOf<PrizeBallBean>()
    private val tou3Balls = mutableListOf<PrizeBallBean>()
    private val tou4Balls = mutableListOf<PrizeBallBean>()
    private val men1Balls = mutableListOf<PrizeBallBean>()
    private val men2Balls = mutableListOf<PrizeBallBean>()
    private val men3Balls = mutableListOf<PrizeBallBean>()
    private val men4Balls = mutableListOf<PrizeBallBean>()
    private val men5Balls = mutableListOf<PrizeBallBean>()
    private val duan1Balls = mutableListOf<PrizeBallBean>()
    private val duan2Balls = mutableListOf<PrizeBallBean>()
    private val duan3Balls = mutableListOf<PrizeBallBean>()
    private val duan4Balls = mutableListOf<PrizeBallBean>()
    private val duan5Balls = mutableListOf<PrizeBallBean>()
    private val duan6Balls = mutableListOf<PrizeBallBean>()
    private val duan7Balls = mutableListOf<PrizeBallBean>()
    private val he1Balls = mutableListOf<PrizeBallBean>()
    private val he2Balls = mutableListOf<PrizeBallBean>()
    private val he3Balls = mutableListOf<PrizeBallBean>()
    private val he4Balls = mutableListOf<PrizeBallBean>()
    private val he5Balls = mutableListOf<PrizeBallBean>()
    private val he6Balls = mutableListOf<PrizeBallBean>()
    private val he7Balls = mutableListOf<PrizeBallBean>()
    private val he8Balls = mutableListOf<PrizeBallBean>()
    private val he9Balls = mutableListOf<PrizeBallBean>()
    private val he10Balls = mutableListOf<PrizeBallBean>()
    private val he11Balls = mutableListOf<PrizeBallBean>()
    private val he12Balls = mutableListOf<PrizeBallBean>()
    private val he13Balls = mutableListOf<PrizeBallBean>()
    private val touDan0Balls = mutableListOf<PrizeBallBean>()
    private val touDan1Balls = mutableListOf<PrizeBallBean>()
    private val touDan2Balls = mutableListOf<PrizeBallBean>()
    private val touDan3Balls = mutableListOf<PrizeBallBean>()
    private val touDan4Balls = mutableListOf<PrizeBallBean>()
    private val touShuang0Balls = mutableListOf<PrizeBallBean>()
    private val touShuang1Balls = mutableListOf<PrizeBallBean>()
    private val touShuang2Balls = mutableListOf<PrizeBallBean>()
    private val touShuang3Balls = mutableListOf<PrizeBallBean>()
    private val touShuang4Balls = mutableListOf<PrizeBallBean>()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityAssistantBinding.inflate(layoutInflater)
        setContentView(binding.root)
        containerId = binding.assistantLlContainer.id
        initView()
    }

    private fun initView() {
        binding.assistantBtnClear.setOnClickListener {
            binding.assistantCbDan.isChecked = false
            binding.assistantCbShuang.isChecked = false

            binding.assistantCbDa.isChecked = false
            binding.assistantCbXiao.isChecked = false

            binding.assistantCbDaDan.isChecked = false
            binding.assistantCbDaShuang.isChecked = false
            binding.assistantCbXiaoDan.isChecked = false
            binding.assistantCbXiaoShuang.isChecked = false

            binding.assistantCbHeDan.isChecked = false
            binding.assistantCbHeShuang.isChecked = false
            binding.assistantCbHeDa.isChecked = false
            binding.assistantCbHeXiao.isChecked = false

            binding.assistantCbJin.isChecked = false
            binding.assistantCbMu.isChecked = false
            binding.assistantCbShui.isChecked = false
            binding.assistantCbHuo.isChecked = false
            binding.assistantCbTu.isChecked = false

            binding.assistantCbHongBo.isChecked = false
            binding.assistantCbLanBo.isChecked = false
            binding.assistantCbLvBo.isChecked = false

            binding.assistantCbJiaQin.isChecked = false
            binding.assistantCbYeShou.isChecked = false

            binding.assistantCbHongDan.isChecked = false
            binding.assistantCbHongShuang.isChecked = false
            binding.assistantCbLanDan.isChecked = false
            binding.assistantCbLanShuang.isChecked = false
            binding.assistantCbLvDan.isChecked = false
            binding.assistantCbLvShuang.isChecked = false

            binding.assistantCbShu.isChecked = false
            binding.assistantCbNiu.isChecked = false
            binding.assistantCbHu.isChecked = false
            binding.assistantCbTuZi.isChecked = false
            binding.assistantCbLong.isChecked = false
            binding.assistantCbShe.isChecked = false
            binding.assistantCbMa.isChecked = false
            binding.assistantCbYang.isChecked = false
            binding.assistantCbHou.isChecked = false
            binding.assistantCbJi.isChecked = false
            binding.assistantCbGou.isChecked = false
            binding.assistantCbZhu.isChecked = false

            binding.assistantCb0wei.isChecked = false
            binding.assistantCb1wei.isChecked = false
            binding.assistantCb2wei.isChecked = false
            binding.assistantCb3wei.isChecked = false
            binding.assistantCb4wei.isChecked = false
            binding.assistantCb5wei.isChecked = false
            binding.assistantCb6wei.isChecked = false
            binding.assistantCb7wei.isChecked = false
            binding.assistantCb8wei.isChecked = false
            binding.assistantCb9wei.isChecked = false
            binding.assistantCbDaWei.isChecked = false
            binding.assistantCbXiaoWei.isChecked = false

            binding.assistantCb0tou.isChecked = false
            binding.assistantCb1tou.isChecked = false
            binding.assistantCb2tou.isChecked = false
            binding.assistantCb3tou.isChecked = false
            binding.assistantCb4tou.isChecked = false

            binding.assistantCb1men.isChecked = false
            binding.assistantCb2men.isChecked = false
            binding.assistantCb3men.isChecked = false
            binding.assistantCb4men.isChecked = false
            binding.assistantCb5men.isChecked = false

            binding.assistantCb1duan.isChecked = false
            binding.assistantCb2duan.isChecked = false
            binding.assistantCb3duan.isChecked = false
            binding.assistantCb4duan.isChecked = false
            binding.assistantCb5duan.isChecked = false
            binding.assistantCb6duan.isChecked = false
            binding.assistantCb7duan.isChecked = false

            binding.assistantCb1he.isChecked = false
            binding.assistantCb2he.isChecked = false
            binding.assistantCb3he.isChecked = false
            binding.assistantCb4he.isChecked = false
            binding.assistantCb5he.isChecked = false
            binding.assistantCb6he.isChecked = false
            binding.assistantCb7he.isChecked = false
            binding.assistantCb8he.isChecked = false
            binding.assistantCb9he.isChecked = false
            binding.assistantCb10he.isChecked = false
            binding.assistantCb11he.isChecked = false
            binding.assistantCb12he.isChecked = false
            binding.assistantCb13he.isChecked = false

            binding.assistantCb0touDan.isChecked = false
            binding.assistantCb1touDan.isChecked = false
            binding.assistantCb2touDan.isChecked = false
            binding.assistantCb3touDan.isChecked = false
            binding.assistantCb4touDan.isChecked = false
            binding.assistantCb0touShuang.isChecked = false
            binding.assistantCb1touShuang.isChecked = false
            binding.assistantCb2touShuang.isChecked = false
            binding.assistantCb3touShuang.isChecked = false
            binding.assistantCb4touShuang.isChecked = false

            single.clear()
            multiDaDanDaShuangXiaoDanXiaoShuang.clear()
            multiHeDanHeShuangHeDaHeXiao.clear()
            multiWuxing.clear()
            multiColor.clear()
            multiColorDanShuang.clear()
            multiShengXiao.clear()
            multiWeiShu.clear()
            multiTouShu.clear()
            multiMenShu.clear()
            multiDuanShu.clear()
            multiHeShu.clear()
            multiTouDAnTouShuang.clear()
        }
        binding.assistantIvRemark.setOnClickListener {
            ARouter.getInstance().build(RouterPath.Query.PAGE_REMARK).navigation()
        }

        binding.assistantIvHelp.setOnClickListener {
            ARouter.getInstance().build(RouterPath.Query.PAGE_HELP).navigation()
        }

        binding.assistantRecyclerView.run {
            layoutManager = GridLayoutManager(this@AssistantActivity, 10)
            adapter = mAdapter
            itemAnimator = DefaultItemAnimator()
            addItemDecoration(SpaceItemDecoration(this@AssistantActivity))
        }

        binding.assistantCbDan.setOnCheckedChangeListener(this)
        binding.assistantCbShuang.setOnCheckedChangeListener(this)

        binding.assistantCbDa.setOnCheckedChangeListener(this)
        binding.assistantCbXiao.setOnCheckedChangeListener(this)

        binding.assistantCbDaDan.setOnCheckedChangeListener(this)
        binding.assistantCbDaShuang.setOnCheckedChangeListener(this)
        binding.assistantCbXiaoDan.setOnCheckedChangeListener(this)
        binding.assistantCbXiaoShuang.setOnCheckedChangeListener(this)

        binding.assistantCbHeDan.setOnCheckedChangeListener(this)
        binding.assistantCbHeShuang.setOnCheckedChangeListener(this)
        binding.assistantCbHeDa.setOnCheckedChangeListener(this)
        binding.assistantCbHeXiao.setOnCheckedChangeListener(this)

        binding.assistantCbJin.setOnCheckedChangeListener(this)
        binding.assistantCbMu.setOnCheckedChangeListener(this)
        binding.assistantCbShui.setOnCheckedChangeListener(this)
        binding.assistantCbHuo.setOnCheckedChangeListener(this)
        binding.assistantCbTu.setOnCheckedChangeListener(this)

        binding.assistantCbHongBo.setOnCheckedChangeListener(this)
        binding.assistantCbLanBo.setOnCheckedChangeListener(this)
        binding.assistantCbLvBo.setOnCheckedChangeListener(this)

        binding.assistantCbJiaQin.setOnCheckedChangeListener(this)
        binding.assistantCbYeShou.setOnCheckedChangeListener(this)

        binding.assistantCbHongDan.setOnCheckedChangeListener(this)
        binding.assistantCbHongShuang.setOnCheckedChangeListener(this)
        binding.assistantCbLanDan.setOnCheckedChangeListener(this)
        binding.assistantCbLanShuang.setOnCheckedChangeListener(this)
        binding.assistantCbLvDan.setOnCheckedChangeListener(this)
        binding.assistantCbLvShuang.setOnCheckedChangeListener(this)

        binding.assistantCbShu.setOnCheckedChangeListener(this)
        binding.assistantCbNiu.setOnCheckedChangeListener(this)
        binding.assistantCbHu.setOnCheckedChangeListener(this)
        binding.assistantCbTuZi.setOnCheckedChangeListener(this)
        binding.assistantCbLong.setOnCheckedChangeListener(this)
        binding.assistantCbShe.setOnCheckedChangeListener(this)
        binding.assistantCbMa.setOnCheckedChangeListener(this)
        binding.assistantCbYang.setOnCheckedChangeListener(this)
        binding.assistantCbHou.setOnCheckedChangeListener(this)
        binding.assistantCbJi.setOnCheckedChangeListener(this)
        binding.assistantCbGou.setOnCheckedChangeListener(this)
        binding.assistantCbZhu.setOnCheckedChangeListener(this)

        binding.assistantCb0wei.setOnCheckedChangeListener(this)
        binding.assistantCb1wei.setOnCheckedChangeListener(this)
        binding.assistantCb2wei.setOnCheckedChangeListener(this)
        binding.assistantCb3wei.setOnCheckedChangeListener(this)
        binding.assistantCb4wei.setOnCheckedChangeListener(this)
        binding.assistantCb5wei.setOnCheckedChangeListener(this)
        binding.assistantCb6wei.setOnCheckedChangeListener(this)
        binding.assistantCb7wei.setOnCheckedChangeListener(this)
        binding.assistantCb8wei.setOnCheckedChangeListener(this)
        binding.assistantCb9wei.setOnCheckedChangeListener(this)
        binding.assistantCbDaWei.setOnCheckedChangeListener(this)
        binding.assistantCbXiaoWei.setOnCheckedChangeListener(this)

        binding.assistantCb0tou.setOnCheckedChangeListener(this)
        binding.assistantCb1tou.setOnCheckedChangeListener(this)
        binding.assistantCb2tou.setOnCheckedChangeListener(this)
        binding.assistantCb3tou.setOnCheckedChangeListener(this)
        binding.assistantCb4tou.setOnCheckedChangeListener(this)

        binding.assistantCb1men.setOnCheckedChangeListener(this)
        binding.assistantCb2men.setOnCheckedChangeListener(this)
        binding.assistantCb3men.setOnCheckedChangeListener(this)
        binding.assistantCb4men.setOnCheckedChangeListener(this)
        binding.assistantCb5men.setOnCheckedChangeListener(this)

        binding.assistantCb1duan.setOnCheckedChangeListener(this)
        binding.assistantCb2duan.setOnCheckedChangeListener(this)
        binding.assistantCb3duan.setOnCheckedChangeListener(this)
        binding.assistantCb4duan.setOnCheckedChangeListener(this)
        binding.assistantCb5duan.setOnCheckedChangeListener(this)
        binding.assistantCb6duan.setOnCheckedChangeListener(this)
        binding.assistantCb7duan.setOnCheckedChangeListener(this)

        binding.assistantCb1he.setOnCheckedChangeListener(this)
        binding.assistantCb2he.setOnCheckedChangeListener(this)
        binding.assistantCb3he.setOnCheckedChangeListener(this)
        binding.assistantCb4he.setOnCheckedChangeListener(this)
        binding.assistantCb5he.setOnCheckedChangeListener(this)
        binding.assistantCb6he.setOnCheckedChangeListener(this)
        binding.assistantCb7he.setOnCheckedChangeListener(this)
        binding.assistantCb8he.setOnCheckedChangeListener(this)
        binding.assistantCb9he.setOnCheckedChangeListener(this)
        binding.assistantCb10he.setOnCheckedChangeListener(this)
        binding.assistantCb11he.setOnCheckedChangeListener(this)
        binding.assistantCb12he.setOnCheckedChangeListener(this)
        binding.assistantCb13he.setOnCheckedChangeListener(this)

        binding.assistantCb0touDan.setOnCheckedChangeListener(this)
        binding.assistantCb1touDan.setOnCheckedChangeListener(this)
        binding.assistantCb2touDan.setOnCheckedChangeListener(this)
        binding.assistantCb3touDan.setOnCheckedChangeListener(this)
        binding.assistantCb4touDan.setOnCheckedChangeListener(this)
        binding.assistantCb0touShuang.setOnCheckedChangeListener(this)
        binding.assistantCb1touShuang.setOnCheckedChangeListener(this)
        binding.assistantCb2touShuang.setOnCheckedChangeListener(this)
        binding.assistantCb3touShuang.setOnCheckedChangeListener(this)
        binding.assistantCb4touShuang.setOnCheckedChangeListener(this)

        assistantViewModel.getPrizeBallList()

        binding.assistantTvBack.setOnClickListener {
            finish()
        }
    }

    override fun observeViewModel() {
        super.observeViewModel()
        observe(assistantViewModel.prizeBallListLiveData, ::handleGetPrizeBallList)
    }

    private fun handleGetPrizeBallList(result: Resource<MutableList<PrizeBallBean>>) {
        when (result) {
            is Resource.Loading -> {
                mDialog.show()
            }
            is Resource.DataError -> {
                mDialog.dismiss()
                if (!TextUtils.isEmpty(result.errorMsg)) {
                    showToast(result.errorMsg)
                } else {
                    showToast("获取信息异常")
                }
            }
            is Resource.Success -> {
                mDialog.dismiss()
                result.data?.apply {
                    for (ball in this) {
                        ball.num = ball.number.toInt()
                        if (ball.danShu) {
                            danBalls.add(ball)
                        } else {
                            shuangBalls.add(ball)
                        }

                        if (ball.daShu) {
                            daBalls.add(ball)
                        } else {
                            xiaoBalls.add(ball)
                        }

                        if (ball.daDan) {
                            daDanBalls.add(ball)
                        }

                        if (ball.daShuang) {
                            daShuangBalls.add(ball)
                        }

                        if (ball.xiaoDan) {
                            xiaoDanBalls.add(ball)
                        }

                        if (ball.xiaoShuang) {
                            xiaoShuangBalls.add(ball)
                        }

                        if (ball.heDan) {
                            heDanBalls.add(ball)
                        }

                        if (ball.heShuang) {
                            heShuangBalls.add(ball)
                        }

                        if (ball.heDa) {
                            heDaBalls.add(ball)
                        }

                        if (ball.heXiao) {
                            heXiaoBalls.add(ball)
                        }

                        when (ball.wuXing) {
                            1 -> jinBalls.add(ball)
                            2 -> muBalls.add(ball)
                            3 -> shuiBalls.add(ball)
                            4 -> huoBalls.add(ball)
                            5 -> tuBalls.add(ball)
                        }

                        when (ball.color) {
                            1 -> {
                                hongBalls.add(ball)
                                if (ball.danShu) {
                                    hongDanBalls.add(ball)
                                } else {
                                    hongShuangBalls.add(ball)
                                }
                            }
                            2 -> {
                                lanBalls.add(ball)
                                if (ball.danShu) {
                                    lanDanBalls.add(ball)
                                } else {
                                    lanShuangBalls.add(ball)
                                }
                            }
                            3 -> {
                                lvBalls.add(ball)
                                if (ball.danShu) {
                                    lvDanBalls.add(ball)
                                } else {
                                    lvShuangBalls.add(ball)
                                }
                            }
                        }

                        if (ball.jiaQin) {
                            jiaQinBalls.add(ball)
                        } else {
                            yeShouBalls.add(ball)
                        }

                        when (ball.animalId) {
                            1 -> shuBalls.add(ball)
                            2 -> niuBalls.add(ball)
                            3 -> huBalls.add(ball)
                            4 -> tuziBalls.add(ball)
                            5 -> longBalls.add(ball)
                            6 -> sheBalls.add(ball)
                            7 -> maBalls.add(ball)
                            8 -> yangBalls.add(ball)
                            9 -> houBalls.add(ball)
                            10 -> jiBalls.add(ball)
                            11 -> gouBalls.add(ball)
                            12 -> zhuBalls.add(ball)
                        }

                        when (ball.weiShu) {
                            0 -> wei0Balls.add(ball)
                            1 -> wei1Balls.add(ball)
                            2 -> wei2Balls.add(ball)
                            3 -> wei3Balls.add(ball)
                            4 -> wei4Balls.add(ball)
                            5 -> wei5Balls.add(ball)
                            6 -> wei6Balls.add(ball)
                            7 -> wei7Balls.add(ball)
                            8 -> wei8Balls.add(ball)
                            9 -> wei9Balls.add(ball)
                        }

                        if (ball.daWei) {
                            daWeiBalls.add(ball)
                        } else {
                            xiaoWeiBalls.add(ball)
                        }

                        when (ball.touShu) {
                            0 -> {
                                tou0Balls.add(ball)
                                if (ball.danShu) {
                                    touDan0Balls.add(ball)
                                } else {
                                    touShuang0Balls.add(ball)
                                }
                            }
                            1 -> {
                                tou1Balls.add(ball)
                                if (ball.danShu) {
                                    touDan1Balls.add(ball)
                                } else {
                                    touShuang1Balls.add(ball)
                                }
                            }
                            2 -> {
                                tou2Balls.add(ball)
                                if (ball.danShu) {
                                    touDan2Balls.add(ball)
                                } else {
                                    touShuang2Balls.add(ball)
                                }
                            }
                            3 -> {
                                tou3Balls.add(ball)
                                if (ball.danShu) {
                                    touDan3Balls.add(ball)
                                } else {
                                    touShuang3Balls.add(ball)
                                }
                            }
                            4 -> {
                                tou4Balls.add(ball)
                                if (ball.danShu) {
                                    touDan4Balls.add(ball)
                                } else {
                                    touShuang4Balls.add(ball)
                                }
                            }
                        }

                        when (ball.menShu) {
                            1 -> men1Balls.add(ball)
                            2 -> men2Balls.add(ball)
                            3 -> men3Balls.add(ball)
                            4 -> men4Balls.add(ball)
                            5 -> men5Balls.add(ball)
                        }

                        when (ball.duanShu) {
                            1 -> duan1Balls.add(ball)
                            2 -> duan2Balls.add(ball)
                            3 -> duan3Balls.add(ball)
                            4 -> duan4Balls.add(ball)
                            5 -> duan5Balls.add(ball)
                            6 -> duan6Balls.add(ball)
                            7 -> duan7Balls.add(ball)
                        }

                        when (ball.heShu) {
                            1 -> he1Balls.add(ball)
                            2 -> he2Balls.add(ball)
                            3 -> he3Balls.add(ball)
                            4 -> he4Balls.add(ball)
                            5 -> he5Balls.add(ball)
                            6 -> he6Balls.add(ball)
                            7 -> he7Balls.add(ball)
                            8 -> he8Balls.add(ball)
                            9 -> he9Balls.add(ball)
                            10 -> he10Balls.add(ball)
                            11 -> he11Balls.add(ball)
                            12 -> he12Balls.add(ball)
                            13 -> he13Balls.add(ball)
                        }
                    }
                    balls[PrizeBallIdx.DAN] = danBalls
                    balls[PrizeBallIdx.SHUANG] = shuangBalls

                    balls[PrizeBallIdx.DA] = daBalls
                    balls[PrizeBallIdx.XIAO] = xiaoBalls

                    balls[PrizeBallIdx.DA_DAN] = daDanBalls
                    balls[PrizeBallIdx.DA_SHUANG] = daShuangBalls
                    balls[PrizeBallIdx.XIAO_DAN] = xiaoDanBalls
                    balls[PrizeBallIdx.XIAO_SHUANG] = xiaoShuangBalls

                    balls[PrizeBallIdx.HE_DAN] = heDanBalls
                    balls[PrizeBallIdx.HE_SHUANG] = heShuangBalls
                    balls[PrizeBallIdx.HE_DA] = heDaBalls
                    balls[PrizeBallIdx.HE_XIAO] = heXiaoBalls

                    balls[PrizeBallIdx.JIN] = jinBalls
                    balls[PrizeBallIdx.MU] = muBalls
                    balls[PrizeBallIdx.SHUI] = shuiBalls
                    balls[PrizeBallIdx.HUO] = huoBalls
                    balls[PrizeBallIdx.TU] = tuBalls

                    balls[PrizeBallIdx.HONG] = hongBalls
                    balls[PrizeBallIdx.LAN] = lanBalls
                    balls[PrizeBallIdx.LV] = lvBalls

                    balls[PrizeBallIdx.JIA_QIN] = jiaQinBalls
                    balls[PrizeBallIdx.YE_SHOU] = yeShouBalls

                    balls[PrizeBallIdx.HONG_DAN] = hongDanBalls
                    balls[PrizeBallIdx.HONG_SHUANG] = hongShuangBalls
                    balls[PrizeBallIdx.LAN_DAN] = lanDanBalls
                    balls[PrizeBallIdx.LAN_SHUANG] = lanShuangBalls
                    balls[PrizeBallIdx.LV_DAN] = lvDanBalls
                    balls[PrizeBallIdx.LV_SHUANG] = lvShuangBalls

                    balls[PrizeBallIdx.SHU] = shuBalls
                    balls[PrizeBallIdx.NIU] = niuBalls
                    balls[PrizeBallIdx.HU] = huBalls
                    balls[PrizeBallIdx.TUZI] = tuziBalls
                    balls[PrizeBallIdx.LONG] = longBalls
                    balls[PrizeBallIdx.SHE] = sheBalls
                    balls[PrizeBallIdx.MA] = maBalls
                    balls[PrizeBallIdx.YANG] = yangBalls
                    balls[PrizeBallIdx.HOU] = houBalls
                    balls[PrizeBallIdx.JI] = lvBalls
                    balls[PrizeBallIdx.GOU] = gouBalls
                    balls[PrizeBallIdx.ZHU] = zhuBalls

                    balls[PrizeBallIdx.WEI0] = wei0Balls
                    balls[PrizeBallIdx.WEI1] = wei1Balls
                    balls[PrizeBallIdx.WEI2] = wei2Balls
                    balls[PrizeBallIdx.WEI3] = wei3Balls
                    balls[PrizeBallIdx.WEI4] = wei4Balls
                    balls[PrizeBallIdx.WEI5] = wei5Balls
                    balls[PrizeBallIdx.WEI6] = wei6Balls
                    balls[PrizeBallIdx.WEI7] = wei7Balls
                    balls[PrizeBallIdx.WEI8] = wei8Balls
                    balls[PrizeBallIdx.WEI9] = wei9Balls
                    balls[PrizeBallIdx.DA_WEI] = daWeiBalls
                    balls[PrizeBallIdx.XIAO_WEI] = xiaoWeiBalls

                    balls[PrizeBallIdx.TOU0] = tou0Balls
                    balls[PrizeBallIdx.TOU1] = tou1Balls
                    balls[PrizeBallIdx.TOU2] = tou2Balls
                    balls[PrizeBallIdx.TOU3] = tou3Balls
                    balls[PrizeBallIdx.TOU4] = tou4Balls

                    balls[PrizeBallIdx.MEN1] = men1Balls
                    balls[PrizeBallIdx.MEN2] = men2Balls
                    balls[PrizeBallIdx.MEN3] = men3Balls
                    balls[PrizeBallIdx.MEN4] = men4Balls
                    balls[PrizeBallIdx.MEN5] = men5Balls

                    balls[PrizeBallIdx.DUAN1] = duan1Balls
                    balls[PrizeBallIdx.DUAN2] = duan2Balls
                    balls[PrizeBallIdx.DUAN3] = duan3Balls
                    balls[PrizeBallIdx.DUAN4] = duan4Balls
                    balls[PrizeBallIdx.DUAN5] = duan5Balls
                    balls[PrizeBallIdx.DUAN6] = duan6Balls
                    balls[PrizeBallIdx.DUAN7] = duan7Balls

                    balls[PrizeBallIdx.HE1] = he1Balls
                    balls[PrizeBallIdx.HE2] = he2Balls
                    balls[PrizeBallIdx.HE3] = he3Balls
                    balls[PrizeBallIdx.HE4] = he4Balls
                    balls[PrizeBallIdx.HE5] = he5Balls
                    balls[PrizeBallIdx.HE6] = he6Balls
                    balls[PrizeBallIdx.HE7] = he7Balls
                    balls[PrizeBallIdx.HE8] = he8Balls
                    balls[PrizeBallIdx.HE9] = he9Balls
                    balls[PrizeBallIdx.HE10] = he10Balls
                    balls[PrizeBallIdx.HE11] = he11Balls
                    balls[PrizeBallIdx.HE12] = he12Balls
                    balls[PrizeBallIdx.HE13] = he13Balls

                    balls[PrizeBallIdx.TOU_DAN0] = touDan0Balls
                    balls[PrizeBallIdx.TOU_DAN1] = touDan1Balls
                    balls[PrizeBallIdx.TOU_DAN2] = touDan2Balls
                    balls[PrizeBallIdx.TOU_DAN3] = touDan3Balls
                    balls[PrizeBallIdx.TOU_DAN4] = touDan4Balls
                    balls[PrizeBallIdx.TOU_SHUANG0] = touShuang0Balls
                    balls[PrizeBallIdx.TOU_SHUANG1] = touShuang1Balls
                    balls[PrizeBallIdx.TOU_SHUANG2] = touShuang2Balls
                    balls[PrizeBallIdx.TOU_SHUANG3] = touShuang3Balls
                    balls[PrizeBallIdx.TOU_SHUANG4] = touShuang4Balls
                }
            }
        }
    }

    override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
        buttonView?.apply {
            when (id) {
                binding.assistantCbDan.id -> {
                    if (isChecked) {
                        binding.assistantCbShuang.isChecked = false
                        single.put(PrizeBallIdx.SHUANG, false)
                    }
                    single.put(PrizeBallIdx.DAN, isChecked)
                }
                binding.assistantCbShuang.id -> {
                    if (isChecked) {
                        binding.assistantCbDan.isChecked = false
                        single.put(PrizeBallIdx.DAN, false)
                    }
                    single.put(PrizeBallIdx.SHUANG, isChecked)
                }
                binding.assistantCbDa.id -> {
                    if (isChecked) {
                        binding.assistantCbXiao.isChecked = false
                        single.put(PrizeBallIdx.XIAO, false)
                    }
                    single.put(PrizeBallIdx.DA, isChecked)
                }
                binding.assistantCbXiao.id -> {
                    if (isChecked) {
                        binding.assistantCbDa.isChecked = false
                        single.put(PrizeBallIdx.DA, false)
                    }
                    single.put(PrizeBallIdx.XIAO, isChecked)

                }
                binding.assistantCbDaDan.id -> {
                    multiDaDanDaShuangXiaoDanXiaoShuang.put(PrizeBallIdx.DA_DAN, isChecked)
                }
                binding.assistantCbDaShuang.id -> {
                    multiDaDanDaShuangXiaoDanXiaoShuang.put(PrizeBallIdx.DA_SHUANG, isChecked)
                }
                binding.assistantCbXiaoDan.id -> {
                    multiDaDanDaShuangXiaoDanXiaoShuang.put(PrizeBallIdx.XIAO_DAN, isChecked)
                }
                binding.assistantCbXiaoShuang.id -> {
                    multiDaDanDaShuangXiaoDanXiaoShuang.put(PrizeBallIdx.XIAO_SHUANG, isChecked)
                }

                binding.assistantCbHeDan.id -> {
                    multiHeDanHeShuangHeDaHeXiao.put(PrizeBallIdx.HE_DAN, isChecked)
                }
                binding.assistantCbHeShuang.id -> {
                    multiHeDanHeShuangHeDaHeXiao.put(PrizeBallIdx.HE_SHUANG, isChecked)
                }
                binding.assistantCbHeDa.id -> {
                    multiHeDanHeShuangHeDaHeXiao.put(PrizeBallIdx.HE_DA, isChecked)
                }
                binding.assistantCbHeXiao.id -> {
                    multiHeDanHeShuangHeDaHeXiao.put(PrizeBallIdx.HE_XIAO, isChecked)
                }
                binding.assistantCbJin.id -> {
                    multiWuxing.put(PrizeBallIdx.JIN, isChecked)
                }
                binding.assistantCbMu.id -> {
                    multiWuxing.put(PrizeBallIdx.MU, isChecked)
                }
                binding.assistantCbShui.id -> {
                    multiWuxing.put(PrizeBallIdx.SHUI, isChecked)
                }
                binding.assistantCbHuo.id -> {
                    multiWuxing.put(PrizeBallIdx.HUO, isChecked)
                }
                binding.assistantCbTu.id -> {
                    multiWuxing.put(PrizeBallIdx.TU, isChecked)
                }
                binding.assistantCbHongBo.id -> {
                    multiColor.put(PrizeBallIdx.HONG, isChecked)
                }
                binding.assistantCbLanBo.id -> {
                    multiColor.put(PrizeBallIdx.LAN, isChecked)
                }
                binding.assistantCbLvBo.id -> {
                    multiColor.put(PrizeBallIdx.LV, isChecked)
                }
                binding.assistantCbJiaQin.id -> {
                    if (isChecked) {
                        binding.assistantCbYeShou.isChecked = false
                        single.put(PrizeBallIdx.YE_SHOU, false)
                    }
                    single.put(PrizeBallIdx.JIA_QIN, isChecked)
                }
                binding.assistantCbYeShou.id -> {
                    if (isChecked) {
                        binding.assistantCbJiaQin.isChecked = false
                        single.put(PrizeBallIdx.JIA_QIN, false)
                    }
                    single.put(PrizeBallIdx.YE_SHOU, isChecked)
                }
                binding.assistantCbHongDan.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.HONG_DAN, isChecked)
                }
                binding.assistantCbHongShuang.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.HONG_SHUANG, isChecked)
                }
                binding.assistantCbLanDan.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.LAN_DAN, isChecked)
                }
                binding.assistantCbLanShuang.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.LAN_SHUANG, isChecked)
                }
                binding.assistantCbLvDan.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.LV_DAN, isChecked)
                }
                binding.assistantCbLvShuang.id -> {
                    multiColorDanShuang.put(PrizeBallIdx.LV_SHUANG, isChecked)
                }
                binding.assistantCbShu.id -> {
                    multiShengXiao.put(PrizeBallIdx.SHU, isChecked)
                }
                binding.assistantCbNiu.id -> {
                    multiShengXiao.put(PrizeBallIdx.NIU, isChecked)
                }
                binding.assistantCbHu.id -> {
                    multiShengXiao.put(PrizeBallIdx.HU, isChecked)
                }
                binding.assistantCbTuZi.id -> {
                    multiShengXiao.put(PrizeBallIdx.TUZI, isChecked)
                }
                binding.assistantCbLong.id -> {
                    multiShengXiao.put(PrizeBallIdx.LONG, isChecked)
                }
                binding.assistantCbShe.id -> {
                    multiShengXiao.put(PrizeBallIdx.SHE, isChecked)
                }
                binding.assistantCbMa.id -> {
                    multiShengXiao.put(PrizeBallIdx.MA, isChecked)
                }
                binding.assistantCbYang.id -> {
                    multiShengXiao.put(PrizeBallIdx.YANG, isChecked)
                }
                binding.assistantCbHou.id -> {
                    multiShengXiao.put(PrizeBallIdx.HOU, isChecked)
                }
                binding.assistantCbJi.id -> {
                    multiShengXiao.put(PrizeBallIdx.JI, isChecked)
                }
                binding.assistantCbGou.id -> {
                    multiShengXiao.put(PrizeBallIdx.GOU, isChecked)
                }
                binding.assistantCbZhu.id -> {
                    multiShengXiao.put(PrizeBallIdx.ZHU, isChecked)
                }
                binding.assistantCb0wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI0, isChecked)
                }
                binding.assistantCb1wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI1, isChecked)
                }
                binding.assistantCb2wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI2, isChecked)
                }
                binding.assistantCb3wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI3, isChecked)
                }
                binding.assistantCb4wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI4, isChecked)
                }
                binding.assistantCb5wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI5, isChecked)
                }
                binding.assistantCb6wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI6, isChecked)
                }
                binding.assistantCb7wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI7, isChecked)
                }
                binding.assistantCb8wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI8, isChecked)
                }
                binding.assistantCb9wei.id -> {
                    multiWeiShu.put(PrizeBallIdx.WEI9, isChecked)
                }
                binding.assistantCbDaWei.id -> {
                    multiWeiShu.put(PrizeBallIdx.DA_WEI, isChecked)
                }
                binding.assistantCbXiaoWei.id -> {
                    multiWeiShu.put(PrizeBallIdx.XIAO_WEI, isChecked)
                }
                binding.assistantCb0tou.id -> {
                    multiTouShu.put(PrizeBallIdx.TOU0, isChecked)
                }
                binding.assistantCb1tou.id -> {
                    multiTouShu.put(PrizeBallIdx.TOU1, isChecked)
                }
                binding.assistantCb2tou.id -> {
                    multiTouShu.put(PrizeBallIdx.TOU2, isChecked)
                }
                binding.assistantCb3tou.id -> {
                    multiTouShu.put(PrizeBallIdx.TOU3, isChecked)
                }
                binding.assistantCb4tou.id -> {
                    multiTouShu.put(PrizeBallIdx.TOU4, isChecked)
                }
                binding.assistantCb1men.id -> {
                    multiMenShu.put(PrizeBallIdx.MEN1, isChecked)
                }
                binding.assistantCb2men.id -> {
                    multiMenShu.put(PrizeBallIdx.MEN2, isChecked)
                }
                binding.assistantCb3men.id -> {
                    multiMenShu.put(PrizeBallIdx.MEN3, isChecked)
                }
                binding.assistantCb4men.id -> {
                    multiMenShu.put(PrizeBallIdx.MEN4, isChecked)
                }
                binding.assistantCb5men.id -> {
                    multiMenShu.put(PrizeBallIdx.MEN5, isChecked)
                }
                binding.assistantCb1duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN1, isChecked)
                }
                binding.assistantCb2duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN2, isChecked)
                }
                binding.assistantCb3duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN3, isChecked)
                }
                binding.assistantCb4duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN4, isChecked)
                }
                binding.assistantCb5duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN5, isChecked)
                }
                binding.assistantCb6duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN6, isChecked)
                }
                binding.assistantCb7duan.id -> {
                    multiDuanShu.put(PrizeBallIdx.DUAN7, isChecked)
                }
                binding.assistantCb1he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE1, isChecked)
                }
                binding.assistantCb2he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE2, isChecked)
                }
                binding.assistantCb3he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE3, isChecked)
                }
                binding.assistantCb4he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE4, isChecked)
                }
                binding.assistantCb5he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE5, isChecked)
                }
                binding.assistantCb6he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE6, isChecked)
                }
                binding.assistantCb7he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE7, isChecked)
                }
                binding.assistantCb8he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE8, isChecked)
                }
                binding.assistantCb9he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE9, isChecked)
                }
                binding.assistantCb10he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE10, isChecked)
                }
                binding.assistantCb11he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE11, isChecked)
                }
                binding.assistantCb12he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE12, isChecked)
                }
                binding.assistantCb13he.id -> {
                    multiHeShu.put(PrizeBallIdx.HE13, isChecked)
                }
                binding.assistantCb0touDan.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_DAN0, isChecked)
                }
                binding.assistantCb1touDan.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_DAN1, isChecked)
                }
                binding.assistantCb2touDan.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_DAN2, isChecked)
                }
                binding.assistantCb3touDan.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_DAN3, isChecked)
                }
                binding.assistantCb4touDan.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_DAN4, isChecked)
                }
                binding.assistantCb0touShuang.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_SHUANG0, isChecked)
                }
                binding.assistantCb1touShuang.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_SHUANG1, isChecked)
                }
                binding.assistantCb2touShuang.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_SHUANG2, isChecked)
                }
                binding.assistantCb3touShuang.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_SHUANG3, isChecked)
                }
                binding.assistantCb4touShuang.id -> {
                    multiTouDAnTouShuang.put(PrizeBallIdx.TOU_SHUANG4, isChecked)
                }
            }
            mAdapter.setList(filterBalls())
        }
    }

    private fun filterBalls(): MutableList<PrizeBallBean> {
        var singleBalls = mutableListOf<PrizeBallBean>()
        val multiBalls = mutableListOf<MutableList<PrizeBallBean>>()
        var multiDaDanDaShuangXiaoDanXiaoShuangBalls = mutableListOf<PrizeBallBean>()
        var multiHeDanHeShuangHeDaHeXiaoBalls = mutableListOf<PrizeBallBean>()
        var multiWuxingBalls = mutableListOf<PrizeBallBean>()
        var multiColorBalls = mutableListOf<PrizeBallBean>()
        var multiColorDanShuangBalls = mutableListOf<PrizeBallBean>()
        var multiShengXiaoBalls = mutableListOf<PrizeBallBean>()
        var multiWeiShuBalls = mutableListOf<PrizeBallBean>()
        var multiTouShuBalls = mutableListOf<PrizeBallBean>()
        var multiMenShuBalls = mutableListOf<PrizeBallBean>()
        var multiDuanShuBalls = mutableListOf<PrizeBallBean>()
        var multiHeShuBalls = mutableListOf<PrizeBallBean>()
        var multiTouDAnTouShuangBalls = mutableListOf<PrizeBallBean>()

        if (single.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = single[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    singleBalls = intersectionBalls(idxBalls, singleBalls)
                }
            }
        }
        if (multiDaDanDaShuangXiaoDanXiaoShuang.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiDaDanDaShuangXiaoDanXiaoShuang[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiDaDanDaShuangXiaoDanXiaoShuangBalls = completeBalls(idxBalls, multiDaDanDaShuangXiaoDanXiaoShuangBalls)
                }
            }
        }
        if (multiHeDanHeShuangHeDaHeXiao.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiHeDanHeShuangHeDaHeXiao[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiHeDanHeShuangHeDaHeXiaoBalls = completeBalls(idxBalls, multiHeDanHeShuangHeDaHeXiaoBalls)
                }
            }
        }
        if (multiWuxing.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiWuxing[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiWuxingBalls = completeBalls(idxBalls, multiWuxingBalls)
                }
            }
        }
        if (multiColor.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiColor[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiColorBalls = completeBalls(idxBalls, multiColorBalls)
                }
            }
        }
        if (multiColorDanShuang.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiColorDanShuang[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiColorDanShuangBalls = completeBalls(idxBalls, multiColorDanShuangBalls)
                }
            }
        }
        if (multiShengXiao.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiShengXiao[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiShengXiaoBalls = completeBalls(idxBalls, multiShengXiaoBalls)
                }
            }
        }
        if (multiWeiShu.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiWeiShu[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiWeiShuBalls = completeBalls(idxBalls, multiWeiShuBalls)
                }
            }
        }
        if (multiTouShu.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiTouShu[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiTouShuBalls = completeBalls(idxBalls, multiTouShuBalls)
                }
            }
        }
        if (multiMenShu.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiMenShu[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiMenShuBalls = completeBalls(idxBalls, multiMenShuBalls)
                }
            }
        }
        if (multiDuanShu.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiDuanShu[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiDuanShuBalls = completeBalls(idxBalls, multiDuanShuBalls)
                }
            }
        }
        if (multiHeShu.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiHeShu[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiHeShuBalls = completeBalls(idxBalls, multiHeShuBalls)
                }
            }
        }
        if (multiTouDAnTouShuang.isNotEmpty()) {
            for (idx in balls.keys) {
                val idxBalls = balls[idx]
                val checkStatus = multiTouDAnTouShuang[idx]
                if (!idxBalls.isNullOrEmpty() && checkStatus) {
                    multiTouDAnTouShuangBalls = completeBalls(idxBalls, multiTouDAnTouShuangBalls)
                }
            }
        }
        if (multiDaDanDaShuangXiaoDanXiaoShuangBalls.isNotEmpty()) {
            multiBalls.add(multiDaDanDaShuangXiaoDanXiaoShuangBalls)
        }
        if (multiHeDanHeShuangHeDaHeXiaoBalls.isNotEmpty()) {
            multiBalls.add(multiHeDanHeShuangHeDaHeXiaoBalls)
        }
        if (multiWuxingBalls.isNotEmpty()) {
            multiBalls.add(multiWuxingBalls)
        }
        if (multiColorBalls.isNotEmpty()) {
            multiBalls.add(multiColorBalls)
        }
        if (multiColorDanShuangBalls.isNotEmpty()) {
            multiBalls.add(multiColorDanShuangBalls)
        }
        if (multiShengXiaoBalls.isNotEmpty()) {
            multiBalls.add(multiShengXiaoBalls)
        }
        if (multiWeiShuBalls.isNotEmpty()) {
            multiBalls.add(multiWeiShuBalls)
        }
        if (multiTouShuBalls.isNotEmpty()) {
            multiBalls.add(multiTouShuBalls)
        }
        if (multiMenShuBalls.isNotEmpty()) {
            multiBalls.add(multiMenShuBalls)
        }
        if (multiDuanShuBalls.isNotEmpty()) {
            multiBalls.add(multiDuanShuBalls)
        }
        if (multiHeShuBalls.isNotEmpty()) {
            multiBalls.add(multiHeShuBalls)
        }
        if (multiTouDAnTouShuangBalls.isNotEmpty()) {
            multiBalls.add(multiTouDAnTouShuangBalls)
        }
        if (singleBalls.isEmpty() && multiBalls.isEmpty()) {
            return mutableListOf()
        }
        if (singleBalls.isEmpty()) {
            var result = mutableListOf<PrizeBallBean>()
            for (balls in multiBalls) {
                result = intersectionBalls(balls, result)
            }
            return result
        }
        if (multiBalls.isEmpty()) {
            return singleBalls
        }

        var result = mutableListOf<PrizeBallBean>()
        for (balls in multiBalls) {
            result = intersectionBalls(balls, result)
        }
        return intersectionBalls(singleBalls, result)
    }

    private fun intersectionBalls(balls1: MutableList<PrizeBallBean>, balls2: MutableList<PrizeBallBean>): MutableList<PrizeBallBean> {
        val tmp = mutableSetOf<PrizeBallBean>()
        tmp.addAll(balls1.toMutableSet())
        if (balls2.isNotEmpty()) {
            tmp.retainAll(balls2.toMutableSet())
        }
        val result = tmp.toMutableList()
        result.sortBy { it.num }
        return result.toMutableList()
    }

    private fun completeBalls(balls1: MutableList<PrizeBallBean>, balls2: MutableList<PrizeBallBean>): MutableList<PrizeBallBean> {
        val tmp = mutableSetOf<PrizeBallBean>()
        tmp.addAll(balls1.toMutableSet())
        if (balls2.isNotEmpty()) {
            tmp.addAll(balls2.toMutableSet())
        }
        val result = tmp.toMutableList()
        result.sortBy { it.num }
        return result.toMutableList()
    }
}